package com.itheima.dao;

import com.itheima.bean.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class StudentTest04 {
    public static void main(String[] args) throws Exception{
        // 加载核心配置文件
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");

        // 获取SqlSession工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);

        // 通过sqlSession工厂对象获取SqlSession对象
        SqlSession sqlSession = sqlSessionFactory.openSession(true);

        // 执行映射配置文件中的sql语句，并接收结果
        Student stu = new Student(6,"徐振益",8);
        int i = sqlSession.insert("StudentMapper.update", stu);

        // 释放资源
        sqlSession.close();
        is.close();
    }
}
